<template>
  <van-uploader
      v-model="list"
      :max-count="maxCount"
      :beforeRead="beforeRead"
      :before-delete="delImg"
      :accept="accept"
  />
</template>

<script>
export default {
name: "index",
  props:{
  //上传图片最大值
  maxCount:{
    type:Number,
    default:1
  },
    accept:{
    type:String,
      default:'.jpeg,.jpg,.png'
    }
  },
  data(){
  return {
    //图片
    list:[]
  }
  },
  methods: {
  //上传图片
    beforeRead(file){
      if (file.type !== "image/jpeg" && file.type !== "image/png") {
        return this.$toast(`请上传${this.accept}格式的图片`);
      } if(file.type !== "video/*"){
        return this.$toast(`请上传${this.accept}格式的视频`);
      }
      this.$emit('beforeRead',this.maxCount,file)
    },
    //删除
    delImg(file){
      this.$emit('delImg',file)
    }
  }
}
</script>

<style scoped lang="less">
/deep/.van-uploader__input-wrapper{
  width: 100%;
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
  padding: 15px;
  img{
    width: 40px;
    height: 40px;
    display: block;
  }
}
</style>
